package Threadtext;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-03-30
 * Time: 11:01
 */
class MyBlockingQueue{
    private int[] items = new int[1000];
    private int head = 0;
    private int tail = 0;
    private int size = 0;
    public void put(int value){
        if(size == items.length){
            return;
        }
        items[tail] = value;
        tail++;
        //1)
//        tail = tail % items.length;
        //2)
        if(tail >= items.length){
            tail = 0;
        }
        size++;
    }
    public Integer take(){
        if(size == 0){
            return null;
        }
        int result = items[head];
        head++;
        if(head >= items.length){
            head = 0;
        }
        size --;
        return result;
    }
}
public class Thread3 {
    public static void main(String[] args) {
        MyBlockingQueue queue = new MyBlockingQueue();

    }
}
